package main

import (
	"ginplay/myansible"
	"ginplay/myplay"
	"ginplay/myproxy"
	"ginplay/mytool"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	cfg := mytool.Getconfig()
	username := cfg.Section("").Key("username").String()
	password := cfg.Section("").Key("password").String()
	port := cfg.Section("").Key("port").String()
	r.Use(gin.BasicAuth(gin.Accounts{
		username: password,
	}))
	r.GET("/", func(c *gin.Context) {
		c.Redirect(http.StatusFound, "/static/myplay.html")
	})
	r.Static("/static", "./static")
	r.POST("/myplay/GetByPage", myplay.GetByPage)
	r.POST("/myplay/Realadd", myplay.Realadd)
	r.POST("/myplay/Multidelete", myplay.Multidelete)
	r.POST("/myplay/Update", myplay.Update)
	r.GET("/myplay/GetById", myplay.GetById)
	r.GET("/myplay/DeleteById", myplay.DeleteById)
	r.GET("/myplay/CopyById", myplay.CopyById)
	r.GET("/myplay/RunById", myplay.RunById)
	r.GET("/myplay/Getlog", myplay.Getlog)

	r.POST("/myproxy/GetByPage", myproxy.GetByPage)
	r.POST("/myproxy/Realadd", myproxy.Realadd)
	r.POST("/myproxy/Update", myproxy.Update)
	r.GET("/myproxy/GetById", myproxy.GetById)
	r.GET("/myproxy/Getnames", myproxy.Getnames)
	r.GET("/myproxy/DeleteById", myproxy.DeleteById)

	r.POST("/myansible/GetByPage", myansible.GetByPage)
	r.POST("/myansible/Realadd", myansible.Realadd)
	r.GET("/myansible/GetById", myansible.GetById)
	r.POST("/myansible/Update", myansible.Update)
	r.GET("/myansible/DeleteById", myansible.DeleteById)
	r.GET("/myansible/CopyById", myansible.CopyById)
	r.GET("/myansible/RunById", myansible.RunById)
	r.GET("/myansible/Getlog", myansible.Getlog)
	myplay.CheckTable()
	myproxy.CheckTable()
	myansible.CheckTable()
	r.Run(":" + port)
}
